﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using JoltEnvironment.Sql;

namespace WorldServer
{
    public static class ServerManager
    {
        #region Methods

        /// <summary>
        /// Gets world info from world id.
        /// </summary>
        /// <param name="WorldID">World id.</param>
        /// <returns>World info.</returns>
        public static World GetWorld(int WorldID)
        {
            DataRow WorldRow = null;

            using (SqlDatabaseClient Client = Program.DatabaseManager.GetClient())
            {
                Client.AddParameter("id", WorldID);

                WorldRow = Client.ReadDataRow("SELECT * FROM server_tbl WHERE id=@id;");
            }

            if (WorldRow == null)
            {
                throw new Exception();
            }
            else
            {
                World WorldData = new World();

                WorldData.ParentID = (int)WorldRow["parent_id"];
                WorldData.WorldID = WorldID;

                WorldData.WorldName = (string)WorldRow["name"];
                WorldData.WorldIP = (string)WorldRow["ip"];

                WorldData.Enabled = (int)WorldRow["enabled"];
                WorldData.OnlineLimit = (int)WorldRow["online_limit"];

                return WorldData;
            }
        }

        #endregion
    }

    public struct World
    {
        public int ParentID;
        public int WorldID;

        public string WorldName;
        public string WorldIP;

        public int Enabled;
        public int OnlineLimit;
    }
}
